<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="false">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row :gutter="48">
          <a-col :span="24">
            <a-form-model-item label="源单类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsourcetype">
              <a-input :disabled=formDisabled v-model="model.fsourcetype" :max-length="36"  placeholder="请输入源单类型"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="源单编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsrcbillno">
              <a-input :disabled=formDisabled v-model="model.fsrcbillno" :max-length="36"  placeholder="请输入源单编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算方式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsrcsettletypeiddata">
              <a-input :disabled=formDisabled v-model="model.fsrcsettletypeiddata" :max-length="36"  placeholder="请输入结算方式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="应付金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fafttaxtotalamount">
              <a-input-number :disabled=formDisabled :max="999999999" :min="0" :precision="2" v-model="model.fafttaxtotalamount" placeholder="请输入应付金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="本次付款金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="frealpayamounts">
              <a-input-number :disabled=formDisabled :max="999999999" :min="0" :precision="2" v-model="model.frealpayamounts" placeholder="请输入本次付款金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="付款用途" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fpaypurposeiddata">
              <a-input :disabled=formDisabled v-model="model.fpaypurposeiddata" :max-length="36"  placeholder="请输入付款用途"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用项目" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsrccostiddata">
              <a-input :disabled=formDisabled v-model="model.fsrccostiddata" :max-length="36"  placeholder="请输入费用项目"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="费用承担部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fexpensedeptiddata">
              <a-input :disabled=formDisabled v-model="model.fexpensedeptiddata" :max-length="36"  placeholder="请输入费用承担部门"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="源单币别" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsrccurrencyid">
              <a-input :disabled=formDisabled v-model="model.fsrccurrencyid" :max-length="36"  placeholder="请输入源单币别"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="计划金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fplanpayamount">
              <a-input-number :disabled=formDisabled :max="999999999" :min="0" :precision="2" v-model="model.fplanpayamount" placeholder="请输入计划金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="转换规则" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fruleid">
              <a-input :disabled=formDisabled v-model="model.fruleid" :max-length="36"  placeholder="请输入转换规则"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="源单表" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fstablename">
              <a-input :disabled=formDisabled v-model="model.fstablename" :max-length="36"  placeholder="请输入源单表"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="源单内码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsbillid">
              <a-input :disabled=formDisabled v-model="model.fsbillid" :max-length="36"  placeholder="请输入源单内码"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="分录内码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fsid">
              <a-input :disabled=formDisabled v-model="model.fsid" :max-length="36"  placeholder="请输入分录内码"  ></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'
  import SelectUserByDep from '@/views/scy/components/SelectUserByDep'
  import SelectTeamInput from '@/views/scy/components/SelectTeamInput'
  import SelectCompanyInput from '@/views/scy/components/SelectCompanyInput'
  import SelectCustomerInput from '@/views/scy/components/SelectCustomerInput'
  import moment from 'moment'
  import { mapGetters } from 'vuex'

  export default {
    name: 'ErpFinanceKingdeePaymentLinkForm',
    components: {
      SelectUserByDep,
      SelectTeamInput,
      SelectCompanyInput,
      SelectCustomerInput
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 24 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/api/erp/finance/kingdee/payment/erpFinanceKingdeePaymentLink/add",
          edit: "/api/erp/finance/kingdee/payment/erpFinanceKingdeePaymentLink/edit",
          queryById: "/api/erp/finance/kingdee/payment/erpFinanceKingdeePaymentLink/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      ...mapGetters(['userInfo']),
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.$refs.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
                that.$emit('unButtonDisable');
              }
            }).catch((error)=>{
               that.$emit('unButtonDisable');
             }).finally(() => {
               that.confirmLoading = false;
             })
          }else {
           that.$emit('unButtonDisable');
          }

        })
      },
    }
  }
</script>
